package xyz.xiaomeiqiu.study.starter;


import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import xyz.xiaomeiqiu.study.domain.Klass;
import xyz.xiaomeiqiu.study.domain.School;

import java.util.List;

@Configuration
@EnableConfigurationProperties(School.class)
@ConditionalOnClass(School.class)
@ConditionalOnProperty(prefix = "xiaomeiqiu.school", value = "enabled", matchIfMissing = true)
public class SchoolConfiguration {
    private String name;

    private List<Klass> classes;

    @Bean
    @ConditionalOnMissingBean(School.class)
    public School school() {
        return new School(name, classes);
    }

}
